package com.wyp168.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @ClassName DistinctSubseqIISolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/14 09:00
 */
public class DistinctSubseqIISolution {
    public static void main(String[] args) {
        DistinctSubseqIISolution solution = new DistinctSubseqIISolution();
        String s = "abc";

        System.out.println(solution.distinctSubseqII(s));
    }

    public int distinctSubseqII(String s) {
        Set<String> set = new HashSet<>();
        int length = s.length();

        int result = 0;

        int left = 0;

        while (left < length) {
            int right = left + 1;
            while (right < length) {
                if (set.add(s.substring(left, right ++))) {
                    result ++;
                }
            }
            if (set.add(s.substring(left))) {
                result ++;
            }
            left ++;
        }
//        if (set.add(s.substring(s.length() - 1))) {
//            return ++result;
//        }
        return result;
    }
}
